Constants

INIT_WITH_DB

INIT_WITH_DB = 1

INIT_WITH_PLUGINS

INIT_WITH_PLUGINS = 2

REQUEST_VALID

REQUEST_VALID = 0

REQUEST_ERROR_URL

REQUEST_ERROR_URL = 1

REQUEST_ERROR_TOKEN

REQUEST_ERROR_TOKEN = 2

DEBUG_LINE_LENGTH

DEBUG_LINE_LENGTH = 4096

Properties

$config

$config : \rcube_config

Type

rcube_config — Stores instance of rcube_config

$db

$db : \rcube_db

Type

rcube_db — Instance of database class

$memcache

$memcache : \Memcache

Type

\Memcache — Instance of Memcache class

$memcached

$memcached : \Memcached

Type

\Memcached — Instance of Memcached class

$redis

$redis : \Redis

Type

\Redis — Instance of Redis class

$session

$session : \rcube_session

Type

rcube_session — Instance of rcube_session class

$smtp

$smtp : \rcube_smtp

Type

rcube_smtp — Instance of rcube_smtp class

$storage

$storage : \rcube_storage

Type

rcube_storage — Instance of rcube_storage class

$output

$output : \rcube_output

Type

rcube_output — Instance of rcube_output class

$plugins

$plugins : \rcube_plugin_api

Type

rcube_plugin_api — Instance of rcube_plugin_api

$user

$user : \rcube_user

Type

rcube_user — Instance of rcube_user class

$request_status

$request_status : int

Type

int — Request status

$texts

$texts : array

Type

array — Localization

$caches

$caches : \rcube_cache[]

Type

rcube_cache[] — Initialized cache objects

$shutdown_functions

$shutdown_functions : array

Type

array — Registered shutdown functions

$instance

$instance : \rcube

Type

rcube — Singleton instance of rcube

Methods

get_instance()

get_instance(int  $mode, string  $env = '') : \rcube

This implements the 'singleton' design pattern

Parameters

int $mode

Options to initialize with this instance. See rcube::INIT_WITH_* constants

string $env

Environment name to run (e.g. live, dev, test)

Returns

\rcube —

The one and only instance

get_dbh()

get_dbh() : \rcube_db

Get the current database connection

Returns

\rcube_db —

Database object

get_memcache()

get_memcache() : \Memcache

Get global handle for memcache access

Returns

\Memcache —

The memcache engine

get_memcached()

get_memcached() : \Memcached

Get global handle for memcached access

Returns

\Memcached —

The memcached engine

get_redis()

get_redis() : \Redis

Get global handle for redis access

Returns

\Redis —

The redis engine

get_cache()

get_cache(string  $name, string  $type = 'db', string  $ttl, bool  $packed = true, bool  $indexed = false) : \rcube_cache|null

Initialize and get user cache object

Parameters

string $name

Cache identifier

string $type

Cache type ('db', 'apc', 'memcache', 'redis')

string $ttl

Expiration time for cache items

bool $packed

Enables/disables data serialization

bool $indexed

Use indexed cache

Returns

\rcube_cache|null —

User cache object

get_cache_shared()

get_cache_shared(string  $name, bool  $packed = true) : \rcube_cache

Initialize and get shared cache object

Parameters

string $name

Cache identifier

bool $packed

Enables/disables data serialization

Returns

\rcube_cache —

Shared cache object

get_http_client()

get_http_client(array  $options = []) : \GuzzleHttp\Client

Initialize HTTP client

Parameters

array $options

Configuration options

Returns

\GuzzleHttp\Client —

HTTP client

smtp_init()

smtp_init(bool  $connect = false) : mixed

Create SMTP object and connect to server

Parameters

bool $connect

True if connection should be established

Returns

mixed —

get_storage()

get_storage() : \rcube_storage

Initialize and get storage object

Returns

\rcube_storage —

Storage object

storage_init()

storage_init() : mixed

Initialize storage object

Returns

mixed —

storage_log_session()

storage_log_session(array  $args) : mixed

Callback for IMAP connection events to log session identifiers

Parameters

array $args

Callback arguments

Returns

mixed —

session_init()

session_init() : mixed

Create session object and start the session.

Returns

mixed —

gc()

gc() : mixed

Garbage collector - cache/temp cleaner

Returns

mixed —

gc_temp()

gc_temp() : mixed

Garbage collector function for temp files.

Removes temporary files older than temp_dir_ttl.

Returns

mixed —

gc_run()

gc_run() : mixed

Runs garbage collector with probability based on session settings. This is intended for environments without a session.

Returns

mixed —

gettext()

gettext(mixed  $attrib, string  $domain = null) : string

Get localized text in the desired language

Parameters

mixed $attrib

Named parameters array or label name

string $domain

Label domain (plugin) name

Returns

string —

Localized text

text_exists()

text_exists(string  $name, string  $domain = null, string  $ref_domain = null) : bool

Check if the given text label exists

Parameters

string $name

Label name

string $domain

Label domain (plugin) name or '*' for all domains

string $ref_domain

Sets domain name if label is found

Returns

bool —

True if text exists (either in the current language or in en_US)

load_language()

load_language(string  $lang = null, array  $add = [], array  $merge = []) : mixed

Load a localization package

Parameters

string $lang

Language ID

array $add

Additional text labels/messages

array $merge

Additional text labels/messages to merge

Returns

mixed —

read_localization()

read_localization(string  $dir, string|null  $lang = null) : array

Read localized texts from an additional location (plugins, skins).

Then you can use the result as 2nd arg to load_language().

Parameters

string $dir

Directory to search in

string|null $lang

Language code to read

Returns

array —

Localization labels/messages

read_localization_file()

read_localization_file(string  $file, array  $texts = []) : array

Load localization file

Parameters

string $file

File location

array $texts

Additional texts to merge with

Returns

array —

Localization labels/messages

list_languages()

list_languages() : array

Read directory program/localization and return a list of available languages

Returns

array —

List of available localizations

encrypt()

encrypt(string  $clear, string  $key = 'des_key', bool  $base64 = true) : string|false

Encrypt a string

Parameters

string $clear

Clear text input

string $key

Encryption key to retrieve from the configuration, defaults to 'des_key'

bool $base64

Whether or not to base64_encode() the result before returning

Returns

string|false —

Encrypted text, false on error

decrypt()

decrypt(string  $cipher, string  $key = 'des_key', bool  $base64 = true) : string|false

Decrypt a string

Parameters

string $cipher

Encrypted text

string $key

Encryption key to retrieve from the configuration, defaults to 'des_key'

bool $base64

Whether or not input is base64-encoded

Returns

string|false —

Decrypted text, false on error

get_secure_url_token()

get_secure_url_token(bool  $generate = false) : string|bool

Returns session token for secure URLs

Parameters

bool $generate

Generate token if not exists in session yet

Returns

string|bool —

Token string, False when disabled

get_request_token()

get_request_token() : string

Generate a unique token to be used in a form request

Returns

string —

The request token

check_request()

check_request(int  $mode = rcube_utils::INPUT_POST) : bool

Check if the current request contains a valid token.

Empty requests aren't checked until use_secure_urls is set.

Parameters

int $mode

Request method

Returns

bool —

True if request token is valid false if not

url()

url(mixed  $p) : string

Build a valid URL to this instance of Roundcube

Parameters

mixed $p

Either a string with the action or url parameters as key-value pairs

Returns

string —

Valid application URL

shutdown()

shutdown() : mixed

Function to be executed in script shutdown Registered with register_shutdown_function()

Returns

mixed —

add_shutdown_function()

add_shutdown_function(callable  $function) : mixed

Registers shutdown function to be executed on shutdown.

The functions will be executed before destroying any objects like smtp, imap, session, etc.

Parameters

callable $function

Function callback

Returns

mixed —

sleep()

sleep() : mixed

When you're going to sleep the script execution for a longer time it is good to close all external connections (sql, memcache, redis, SMTP, IMAP).

No action is required on wake up, all connections will be re-established automatically.

Returns

mixed —

Q()

Q(string  $str, string  $mode = 'strict', bool  $newlines = true) : string

Quote a given string.

Shortcut function for rcube_utils::rep_specialchars_output()

Parameters

string $str

A string to quote

string $mode

Replace mode for tags: show|remove|strict

bool $newlines

Convert newlines

Returns

string —

HTML-quoted string

JQ()

JQ(string  $str) : string

Quote a given string for javascript output.

Shortcut function for rcube_utils::rep_specialchars_output()

Parameters

string $str

A string to quote

Returns

string —

JS-quoted string

SQ()

SQ(string  $str) : string

Quote a given string, remove new-line characters, use strict mode.

Shortcut function for rcube_utils::rep_specialchars_output()

Parameters

string $str

A string to quote

Returns

string —

HTML-quoted string

exec()

exec() : string

Construct shell command, execute it and return output as string.

Keywords {keyword} are replaced with arguments

Returns

string —

Output of command. Shell errors not detectable

console()

console() : mixed

Print or write debug messages

Returns

mixed —

write_log()

write_log(string  $name, mixed  $line) : bool

Append a line to a logfile in the logs directory.

Date will be added automatically to the line.

Parameters

string $name

Name of the log file

mixed $line

Line to append

Returns

bool —

True on success, False on failure

raise_error()

raise_error(array  $arg = [], bool  $log = false, bool  $terminate = false) : mixed

Throw system error (and show error page).

Parameters

array $arg

Named parameters

  • code: Error code (required)
  • type: Error type [php|db|imap|javascript]
  • message: Error message
  • file: File where error occurred
  • line: Line where error occurred
bool $log

True to log the error

bool $terminate

Terminate script execution

Returns

mixed —

log_bug()

log_bug(array  $arg_arr) : mixed

Log an error

Parameters

array $arg_arr

Named parameters

Returns

mixed —

debug()

debug(string  $engine, string  $data, bool  $result = null) : mixed

Write debug info to the log

Parameters

string $engine

Engine type - file name (memcache, apc, redis)

string $data

Data string to log

bool $result

Operation result

Returns

mixed —

timer()

timer() : float

Returns current time (with microseconds).

Returns

float —

Current time in seconds since the Unix

print_timer()

print_timer(float  $timer, string  $label = 'Timer', string  $dest = 'console') : mixed

Logs time difference according to provided timer

Parameters

float $timer

Timer (self::timer() result)

string $label

Log line prefix

string $dest

Log file name

Returns

mixed —

set_user()

set_user(mixed  $user) : mixed

Setter for system user object

Parameters

mixed $user

Returns

mixed —

get_user_id()

get_user_id() : mixed

Getter for logged user ID.

Returns

mixed —

User identifier

get_user_name()

get_user_name() : string

Getter for logged user name.

Returns

string —

User name

get_user_email()

get_user_email() : string

Getter for logged user email (derived from user name not identity).

Returns

string —

User email address

get_user_password()

get_user_password() : string

Getter for logged user password.

Returns

string —

User password

get_user_language()

get_user_language() : string

Getter for logged user language code.

Returns

string —

User language code

gen_message_id()

gen_message_id(string  $sender = null) : string

Unique Message-ID generator.

Parameters

string $sender

Optional sender e-mail address

Returns

string —

Message-ID

deliver_message()

deliver_message(\Mail_Mime  $message, string  $from, array|string  $mailto, array|string  $error, string  $body_file = null, array  $options = null, bool  $disconnect = false) : bool

Send the given message using the configured method.

Parameters

\Mail_Mime $message

Reference to Mail_MIME object

string $from

Sender address string

array|string $mailto

Either a comma-separated list of recipients (RFC822 compliant), or an array of recipients, each RFC822 valid

array|string $error

SMTP error array or (deprecated) string

string $body_file

Location of file with saved message body, used when delay_file_io is enabled

array $options

SMTP options (e.g. DSN request)

bool $disconnect

Close SMTP connection ASAP

Returns

bool —

Send status.

__construct()

__construct(string  $env = '') : mixed

Private constructor

Parameters

string $env

Environment name to run (e.g. live, dev, test)

Returns

mixed —

init()

init(int  $mode) : mixed

Initial startup function

Parameters

int $mode

Options to initialize with this instance. See rcube::INIT_WITH_* constants

Returns

mixed —

set_storage_prop()

set_storage_prop() : mixed

Set storage parameters.

Returns

mixed —

set_special_folders()

set_special_folders() : mixed

Set special folders type association.

This must be done AFTER connecting to the server!

Returns

mixed —

language_prop()

language_prop(string  $lang) : string

Check the given string and return a valid language code

Parameters

string $lang

Language code

Returns

string —

Valid language code

get_user_log_dir()

get_user_log_dir() : string|false

Get the per-user log directory

Returns

string|false —

Per-user log directory if it exists and is writable, False otherwise